import 'package:flutter/material.dart';
import 'package:widgets/class/NavigationRailExample.dart';
import 'package:widgets/scroll/gridview_example.dart';
import 'package:widgets/text/RichTextExample.dart';
import 'package:widgets/text/TextSpanExample.dart';

import 'Layout/AlignExample.dart';
import 'Layout/BaselineExample.dart';
import 'Layout/ColumnExample.dart';
import 'Layout/ConstrainedBoxExample.dart';
import 'Layout/FlexibleExample.dart';
import 'Layout/ListView/ListViewExample.dart';
import 'Layout/OffstageExample.dart';
import 'Layout/PaddingExample.dart';
import 'Layout/PositionedExample.dart';
import 'Layout/RowExample.dart';
import 'Layout/SpacerExample.dart';
import 'Layout/StackExample.dart';
import 'Layout/WrapExample.dart';
import 'Navi/AppBarExample01.dart';
import 'Navi/AppBarExample02.dart';
import 'Navi/FlexibleSpaceBarExample.dart';
import 'Navi/TabControllerExample.dart';
import 'Navi/TabControllerExample1.dart';
import 'Navi/TabControllerExample2.dart';
import 'button/DropdownButtonExample.dart';
import 'class/TabBarExample.dart';
import 'dart_io/FutureBuilderExample.dart';
import 'dart_io/FutureExample.dart';
import 'dart_io/IOPlatformExample.dart';
import 'input/FormExample.dart';
import 'input/FormFieldExample.dart';
import 'input/TextFieldExample.dart';

void main() {
  runApp(MyApp());
}

class DataModel {
  final String name;
  final String tag;
  DataModel(this.name, this.tag);
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  // 添加需要展示的 Widget 页面
  final Map<String, WidgetBuilder> routers = {
    '/GridviewExample': (_) => GridviewExample(),
    '/NavigationRailExample': (_) =>
        NavigationRailExample(title: "NavigationRailExample"),
    '/ColumnExample': (_) => ColumnExample(),
    '/RowExample': (_) => RowExample(),
    '/PaddingExample': (_) => PaddingExample(),
    '/AlignExample': (_) => AlignExample(),
    '/BaselineExample': (_) => BaselineExample(),
    '/ConstrainedBoxExample': (_) => ConstrainedBoxExample(),
    '/FlexibleExample': (_) => FlexibleExample(),
    '/SpacerExample': (_) => SpacerExample(),
    '/StackExample': (_) => StackExample(),
    '/PositionedExample': (_) => PositionedExample(),
    '/WrapExample': (_) => WrapExample(),
    '/OffstageExample': (_) => OffstageExample(),
    '/ListViewExample': (_) => ListViewExample(),
    '/TabBarExample': (_) => TabBarExample(),
    '/AppBarExample01': (_) => AppBarExample01(),
    '/AppBarExample02': (_) => AppBarExample02(),
    '/TabControllerExample': (_) => TabControllerExample(),
    '/TabControllerExample1': (_) => TabControllerExample1(),
    '/TabControllerExample2': (_) => TabControllerExample2(),
    '/FlexibleSpaceBarExample': (_) => FlexibleSpaceBarExample(),
    '/TextFieldExample': (_) => TextFieldExample(),
    '/FormFieldExample': (_) => FormFieldExample(),
    '/FormExample': (_) => FormExample(),
    '/DropdownButtonExample': (_) => DropdownButtonExample(),
    '/RichTextExample': (_) => RichTextExample(),
    '/TextSpanExample': (_) => TextSpanExample(),
    '/IOPlatformExample': (_) => IOPlatformExample(),
    '/FutureExample': (_) => FutureExample(),
    '/FutureBuilderExample': (_) => FutureBuilderExample(),
  };

  List<DataModel> list = new List();
  @override
  void initState() {
    routers.forEach((key, value) {
      list.add(DataModel(key.substring(1), key));
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      routes: routers,
      home: Builder(
        builder: (BuildContext context) => Scaffold(
          appBar: AppBar(
            title: Text("Widgets Demo"),
          ),
          body: ListView.builder(
              itemCount: list.length,
              itemBuilder: (_, index) {
                return ListTile(
                  title: Text(list[index].name),
                  onTap: () => Navigator.pushNamed(context, list[index].tag),
                );
              }),
        ),
      ),
    );
  }

  void push(DataModel mode) {}
}
